package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

public class LoginDemo {
    public static void main(String[] args) {
        userinfo userinfo = InputUtil.getInputObject(new userinfo(),"欢迎登录","登录");
        try(
                Connection connection = DbUtil.getConnection();
                ){
            Statement statement =connection.createStatement();
            String str = "SELECT id,username,password,nickname,age\n" +
                    "FROM userinfo\n" +
                    "WHERE username = '"+userinfo.getUsername()+"'\n" +
                    "AND password = "+userinfo.getPassword()+" ";
            ResultSet rs  = statement.executeQuery(str);
            if (rs.next()){
                System.out.println("用户登录成功！欢迎你"+rs.getString("nickname"));
            }else {
                System.out.println("登录失败，用户名或密码不正确");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
